package com.allen.study.application.api;

import com.allen.study.application.api.request.EmployeeInfoCreateRequest;
import com.allen.study.application.api.request.EmployeeInfoQueryRequest;
import com.allen.study.application.api.request.EmployeeInfoUpdateRequest;
import com.allen.study.application.api.response.EmployeeInfoQueryResponse;
import com.allen.study.application.api.response.EmployeeInfoResponse;
import com.allen.study.application.service.EmployeeInfoAppService;
import com.allen.study.common.base.ApiPageResponse;
import com.allen.study.common.base.ApiResponse;
import com.allen.study.common.base.Pagination;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 接口
 *
 * @author AllenSun
 * @since 2025-02-26 22:43
 */
@RequestMapping(value = "/4.2.0/employeeinfo")
@RestController
@AllArgsConstructor
@Tag(name = "接口", description = "接口")
public class EmployeeInfoApi {

    /**
     * 应用服务
     */
    private final EmployeeInfoAppService employeeInfoAppService;

    /**
     * 创建
     *
     * @param createRequest 创建对象
     * @return 响应结果
     */
    @PostMapping
    @Operation(summary = "创建", description = "创建")
    public ApiResponse<Void> create(@RequestBody @Valid EmployeeInfoCreateRequest createRequest) {
        return employeeInfoAppService.create(createRequest);
    }

    /**
     * 根据主键删除
     *
     * @param employeeInfoId 主键
     * @return 响应结果
     */
    @DeleteMapping(value = "/{employee_info_id}")
    @Operation(summary = "根据主键删除", description = "根据主键删除")
    public ApiResponse<Void> deleteById(@PathVariable(name = "employee_info_id") String employeeInfoId) {
        return employeeInfoAppService.deleteById(employeeInfoId);
    }

    /**
     * 根据主键更新
     *
     * @param employeeInfoId 主键
     * @param updateRequest 更新对象
     * @return 响应结果
     */
    @PutMapping(value = "/{employee_info_id}")
    @Operation(summary = "根据主键更新", description = "根据主键更新")
    public ApiResponse<Void> updateById(@PathVariable(name = "employee_info_id") String employeeInfoId,
            @RequestBody @Valid EmployeeInfoUpdateRequest updateRequest) {
        return employeeInfoAppService.updateById(employeeInfoId, updateRequest);
    }

    /**
     * 根据主键查询详情
     *
     * @param employeeInfoId 主键
     * @return 响应结果
     */
    @GetMapping(value = "/{employee_info_id}")
    @Operation(summary = "根据主键查询详情", description = "根据主键查询详情")
    public ApiResponse<EmployeeInfoResponse> queryById(@PathVariable(name = "employee_info_id") String employeeInfoId) {
        return employeeInfoAppService.queryById(employeeInfoId);
    }

    /**
     * 分页查询
     *
     * @param pagination   分页
     * @param queryRequest 查询对象
     * @return 响应结果
     */
    @GetMapping
    @Operation(summary = "分页查询", description = "分页查询")
    public ApiPageResponse<EmployeeInfoQueryResponse> query(@Valid Pagination pagination, @Valid EmployeeInfoQueryRequest queryRequest) {
        return employeeInfoAppService.query(pagination, queryRequest);
    }
}
